package com.united.ucts.modules.oss.controller;

import com.united.frame.common.module.result.Result;
import com.united.frame.oss.aliyun.domain.AliOssCallbackResult;
import com.united.frame.oss.aliyun.domain.AliOssPolicyResult;
import com.united.frame.oss.aliyun.service.AliOssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 阿里云OSS对象存储管理相关操作接口
 *
 * @author Hudan
 * @version 1.0
 * @filename AliOssController.java
 * @copyright <a href="www.united.cn">www.united.cn</a>
 * @date 2019-08-04
 */
@Api(tags = "AliOssController", value = "阿里云OSS管理")
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/oss/aliyun")
public class AliOssController {

    private final AliOssService aliOssService;

    @ApiOperation(value = "oss上传签名生成")
    @GetMapping(value = "/policy")
    public Result<AliOssPolicyResult> policy() {
        AliOssPolicyResult result = aliOssService.policy();
        return Result.success(result);
    }

    @ApiOperation(value = "oss上传成功回调")
    @RequestMapping(value = "callback")
    public Result<AliOssCallbackResult> callback(HttpServletRequest request) {
        AliOssCallbackResult ossCallbackResult = aliOssService.callback(request);
        return Result.success(ossCallbackResult);
    }
}